const mockDatabase = require('./src/config/mockDatabase');

async function debugExistingItems() {
  console.log('=== 调试现有菜单项 ===');
  
  try {
    // 1. 查询所有现有菜单项
    const allItems = await mockDatabase.query('SELECT * FROM menu_items WHERE deleted_at IS NULL');
    console.log('\n现有菜单项:');
    allItems.forEach(item => {
      console.log(`ID: ${item.id}, 名称: ${item.name}, 英文名: ${item.name_en}, 规范化名称: ${item.normalized_name}`);
    });
    
    // 2. 测试V2导入系统的查询逻辑
    console.log('\n=== 测试V2导入查询逻辑 ===');
    
    // 测试通过normalized_name查找
    const testNormalizedNames = ['test-burger-1', 'test-drink-1', 'classic-burger', 'cola'];
    for (const normalizedName of testNormalizedNames) {
      const result = await mockDatabase.query('SELECT * FROM menu_items WHERE normalized_name = ? AND deleted_at IS NULL', [normalizedName]);
      console.log(`查找 normalized_name='${normalizedName}': ${result.length > 0 ? `找到ID=${result[0].id}, 名称=${result[0].name}` : '未找到'}`);
    }
    
    // 测试通过name_en查找
    const testNameEns = ['Test Burger 1', 'Test Drink 1', 'Classic Burger', 'Cola'];
    for (const nameEn of testNameEns) {
      const result = await mockDatabase.query('SELECT * FROM menu_items WHERE name_en = ? AND deleted_at IS NULL', [nameEn]);
      console.log(`查找 name_en='${nameEn}': ${result.length > 0 ? `找到ID=${result[0].id}, 名称=${result[0].name}` : '未找到'}`);
    }
    
  } catch (error) {
    console.error('调试过程中出错:', error);
  }
}

debugExistingItems();